import numpy as np
import cv2

# 获取视频
cap = cv2.VideoCapture('E:\\BaiduNetdiskDownload\\E01.mp4')
# 为什么不行？？
# cap = cv2.VideoCapture("output.avi")
## =>>
# 编码格式对应关系 *'MJPG' -> avi   *'mp4v' --> mp4
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

# 获取原视频的fps
fps = cap.get(5)

print(width, height, fps);
out = cv2.VideoWriter('output.mp4', fourcc, fps, (width, height))

# 因为要一直读，所以用循环
while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        break

    out.write(frame)
    cv2.imshow('video', frame)

    # 根据视频的帧率， 1000 / 视频的帧率
    key = cv2.waitKey(1)
    if(key & 0xFF == ord('q')):
        break

# 释放VideoCapture
cap.release()
out.release()
cv2.destroyAllWindows()